/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2016 All Rights Reserved.
 */
package utils;

//import org.apache.commons.lang.StringUtils;

import org.apache.commons.lang3.StringUtils;

/**
 * @author qiang4.lq4
 * @version $Id: StringUtil.java, v 0.1 2016-12-12 22:38 qiang4.lq4 Exp $$
 */
public class StringUtil {
    public static String alignRight(String origin, String replace, int num) {
        String tmp = origin;
        if (StringUtils.isBlank(origin)) {
            tmp = "";
        }
        String tmpR = replace;
        if (StringUtils.isBlank(replace)) {
            tmpR = "_";
        }
        String reverseTmp = StringUtils.reverse(tmp);
        String reverseTmpR = StringUtils.reverse(tmpR);
        StringBuilder sb = new StringBuilder();

        int lengthTmp = reverseTmp.length();
        int lengthTmpR = reverseTmpR.length();

        sb.append(StringUtils.substring(reverseTmp, 0, num));

        if (sb.length() < num) {
            int i =0;
            while (sb.length() < num) {
                sb.append(reverseTmpR.charAt(i % lengthTmpR));
                i++;
            }
        }
        return StringUtils.reverse(sb.toString());
    }

    public static void main(String[] args) {
        String a = alignRight("a", "1", 5);
        System.out.println(a);
    }
}